package com.service.gmall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.service.gmall.common.result.Result;
import com.service.gmall.model.product.BaseTrademark;
import com.service.gmall.product.service.BaseTrademarkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author alpha
 * @className: BaseTradeMarkController
 * @date 2022/8/24 13:49
 * @Description 品牌接口
 */
@Api(tags = "品牌接口")
@RestController
@RequestMapping("/admin/product")
public class BaseTradeMarkController {
    //    /baseTrademark/1/10
    @Autowired
    BaseTrademarkService baseTrademarkService;

    /**
     * @param page pagenum
     * @param limit pagesize
     * @description:  1.分页列表
     * @return: com.service.gmall.common.result.Result
     * @author: alpha
     * @date: 2022/8/24 14:06
     */
    @ApiOperation("分页列表")
    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result baseTrademark(@PathVariable("page") Long page,
                                @PathVariable("limit") Long limit) {
        Page<BaseTrademark> page1 = new Page<>(page,limit);
        Page<BaseTrademark> resultPage = baseTrademarkService.page(page1);
//        resultPage.getRecords();
        return Result.ok(resultPage);
    }

//    baseTrademark/save
    /**
     * @param baseTrademark
     * @description: 2.添加品牌
     * @return: com.service.gmall.common.result.Result
     * @author: alpha
     * @date: 2022/8/24 14:10
     */
    @PostMapping("/baseTrademark/save")
    public Result saveBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }
    /**
     * @param baseTrademark
     * @description: 3.修改品牌
     * @return: com.service.gmall.common.result.Result
     * @author: alpha
     * @date: 2022/8/24 14:16
     */
    @PutMapping("/baseTrademark/update")
    public Result updateBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }
    /**
     * @param id 品牌id
     * @description: 4、删除品牌
     * @return: com.service.gmall.common.result.Result
     * @author: alpha
     * @date: 2022/8/24 14:20
     */
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result deleteBaseTrademark(@PathVariable("id") Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }
    /**
     * @param id 品牌id
     * @description: 5.根据Id获取品牌
     * @return: com.service.gmall.common.result.Result
     * @author: alpha
     * @date: 2022/8/24 14:20
     */
    @GetMapping("/baseTrademark/get/{id}")
    public Result getBaseTrademark(@PathVariable("id") Long id){
        BaseTrademark trademark = baseTrademarkService.getById(id);
        return Result.ok(trademark);
    }
//    admin/product/baseTrademark/getTrademarkList
    /**
     * @param
     * @description: 6.获取品牌属性
     * @return: com.service.gmall.common.result.Result
     * @author: alpha
     * @date: 2022/8/27 11:17
     */
    @GetMapping("/baseTrademark/getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> list = baseTrademarkService.list();
        return Result.ok(list);
    }
}
